package cn.ronghuanet.user.controller;

import cn.ronghuanet.user.service.ILogininfoService;
import cn.ronghuanet.user.domain.Logininfo;
import cn.ronghuanet.user.query.LogininfoQuery;
import cn.ronghuanet.base.util.AjaxResult;
import cn.ronghuanet.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logininfo")
public class LogininfoController {
    @Autowired
    public ILogininfoService logininfoService;


    /**
     * 保存和修改公用的
     * @param logininfo  传递的实体
     * @return Ajaxresult转换结果
     */
    @PostMapping
    public AjaxResult addOrUpdate(@RequestBody Logininfo logininfo){
        if( logininfo.getId()!=null)
            logininfoService.update(logininfo);
        else
            logininfoService.insert(logininfo);
        return AjaxResult.success();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        logininfoService.delete(id);
        return AjaxResult.success();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable("id")Long id)
    {
        Logininfo logininfo = logininfoService.selectById(id);
        return AjaxResult.success(logininfo);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult list(){
        List< Logininfo> list = logininfoService.selectAll();
        return AjaxResult.success(list);
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PutMapping
    public AjaxResult json(@RequestBody LogininfoQuery query)
    {
        PageInfo<Logininfo> pageList = logininfoService.queryPage(query);
        return AjaxResult.success(pageList);
    }
}
